/**
 * Created by 林 on 2017/3/28 0028.
 */
//////////////////////////////获取元素对象样式////////////////////////////////////
function getStyle(obj,attr) {
    if (obj.currentStyle) {
        return obj.currentStyle[attr];  //IE浏览器获取样式
    } else {
        return getComputedStyle(obj)[attr];  //非IE浏览器获取样式
    }
}
/////////////////////////////////缓冲运动框架/////////////////////////////////////
function startMove(obj,json,fn) {
    clearInterval(obj.timer);
    obj.timer = setInterval(function () {
        var bStop = true;
        for (var attr in json) {
            var iCur = 0;
            if (attr == 'opacity') {
                iCur = Math.round(parseFloat(getStyle(obj, attr)) * 100);
            } else {
                iCur = parseInt(getStyle(obj, attr));
            }
            var speed = (json[attr] - iCur) / 7;
            speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);
            if (iCur != json[attr]) {
                bStop = false;
            }
            if (attr == 'opacity') {
                obj.alpha = 0;
                obj.alpha += speed;
                obj.style.filter = 'alpha(opacity:' + (iCur + obj.alpha) + ')';
                obj.style.opacity = (iCur + obj.alpha) / 100;
            } else {
                obj.style[attr] = iCur + speed + 'px';
            }
        }
        if (bStop) {
            clearInterval(obj.timer);
            if (fn) {
                fn();
            }
        }
    }, 30);
}

/////////////////////////////////匀速运动框架/////////////////////////////////////
function yunSuMove(obj, json, ispeed, fn) {
    clearInterval(obj.timer);
    obj.timer = setInterval(function () {
        var bStop = true;
        for (var attr in json) {
            var iCur = 0;
            if (attr == 'opacity') {
                iCur = Math.round(parseFloat(getStyle(obj, attr)) * 100);
            } else {
                iCur = parseInt(getStyle(obj, attr));
            }


            var speed = 0;
            if (iCur < json[attr]) {
                speed = ispeed;
            } else {
                speed = -ispeed;
            }


            if (iCur != json[attr]) {
                bStop = false;
            }
            if (attr == 'opacity') {
                if (Math.abs(iCur - json[attr]) < 10) {
                    obj.style.filter = 'alpha(opacity:' + json[attr] + ')';
                    obj.style.opacity = json[attr] / 100;
                } else {
                    obj.alpha = 0;
                    obj.alpha += speed;
                    obj.style.filter = 'alpha(opacity:' + (iCur + obj.alpha) + ')';
                    obj.style.opacity = (iCur + obj.alpha) / 100;
                }
            } else {
                if (Math.abs(iCur - json[attr]) < 10) {
                    obj.style[attr] = json[attr] + 'px';
                } else {
                    obj.style[attr] = iCur + speed + 'px';
                }
            }
        }
        if (bStop) {
            clearInterval(obj.timer);//当每个obj本身的所有运动都进行完后清除该obj的定时器
            if (fn) {
                fn();
            }
        }
    }, 10);
}
/////////////////////////////////进度条运动函数/////////////////////////////////////

    function ProgressBar() {
        var oProgressBar = $('.progress').find('.progress-bar');  //获取所有类为progress-bar的元素
        for(var i=0;i<oProgressBar.length;i++){   //循环进度条
            if($(oProgressBar[i]).hasClass('action')) {  //是否含有触发运动的类
                yunSuMove(oProgressBar[i], {width:300}, 4);  //匀速运动
                // startMove(oProgressBar[i], {width: 600}); //缓冲运动
                //         $(oProgressBar[i]).css({
                //             'width':'80%'
                //         });
            }
        }
        // $(oProgressBar[0]).css({'width':'80%'});
    }

/////////////////////////////设置可关闭警告框的关闭动画///////////////////////////////
(function () {
    var oClose = $('.alert-dismissible .close');
    oClose.click(function(){
        if($(this).hasClass('close-slideUp')){
            $(this).parent().slideUp(1000);
        }else if($(this).hasClass('close-hide')){
            $(this).parent().hide(1000);
        }else if($(this).hasClass('close-fadeOut')){
            $(this).parent().fadeOut(1000);
        }else {
            $(this).parent().hide(0);
        }
    });
})();
/////////////////////////////滚动监听///////////////////////////////
(function () {
    var scrollDiv1 = $('.scroll li:nth-child(1)');
    var scrollDiv2 = $('.scroll li:nth-child(2)');
    var scrollDiv3 = $('.scroll li:nth-child(3)');
    var scrollDiv4 = $('.scroll li:nth-child(4)');
    var scrollDiv5 = $('.scroll li:nth-child(5)');
    var scrollDiv6 = $('.scroll li:nth-child(6)');
    var scrollDiv7 = $('.scroll li:nth-child(7)');

    var scrollDiv1Height = $('.scroll-item div:nth-child(1)').height();
    var scrollDiv2Height = $('.scroll-item div:nth-child(2)').height();
    var scrollDiv3Height = $('.scroll-item div:nth-child(3)').height();
    var scrollDiv4Height = $('.scroll-item div:nth-child(4)').height();
    var scrollDiv5Height = $('.scroll-item div:nth-child(5)').height();
    var scrollDiv6Height = $('.scroll-item div:nth-child(6)').height();
    scrollDiv1.click(function () {
        $('.scroll-item').scrollTop(0);
    });
    scrollDiv2.click(function () {
        $('.scroll-item').scrollTop(scrollDiv1Height);
    });

    scrollDiv3.click(function () {
        $('.scroll-item').scrollTop(scrollDiv1Height + scrollDiv2Height);
    });

    scrollDiv4.click(function () {
        $('.scroll-item').scrollTop(scrollDiv1Height + scrollDiv2Height + scrollDiv3Height);
    });
    scrollDiv5.click(function () {
        $('.scroll-item').scrollTop(scrollDiv1Height + scrollDiv2Height + scrollDiv3Height + scrollDiv4Height);
    });
    scrollDiv6.click(function () {
        $('.scroll-item').scrollTop(scrollDiv1Height + scrollDiv2Height + scrollDiv3Height + scrollDiv4Height + scrollDiv5Height);
    });
    scrollDiv7.click(function () {
        $('.scroll-item').scrollTop(scrollDiv1Height + scrollDiv2Height + scrollDiv3Height + scrollDiv4Height + scrollDiv5Height + scrollDiv6Height);
    });

    $('.scroll-item').scroll(function () {
        if( $('.scroll-item').scrollTop() < scrollDiv1Height ){
            for(var i=0;i<$('.nav-pills li').length;i++){
                $('.nav-pills li').removeClass('active');
            }
            $('.nav-pills li:nth-of-type(1)').addClass('active');

        }else if( $('.scroll-item').scrollTop() > scrollDiv1Height && $('.scroll-item').scrollTop() < scrollDiv1Height + scrollDiv2Height ){
            for(i=0;i<$('.nav-pills li').length;i++){
                $('.nav-pills li').removeClass('active');
            }
            $('.nav-pills li:nth-of-type(2)').addClass('active');

        }else if( $('.scroll-item').scrollTop() > scrollDiv1Height +scrollDiv2Height && $('.scroll-item').scrollTop() < scrollDiv1Height + scrollDiv2Height + scrollDiv3Height ){
            for(i=0;i<$('.nav-pills li').length;i++){
                $('.nav-pills li').removeClass('active');
            }
            $('.nav-pills li:nth-of-type(3)').addClass('active');

        }else if( $('.scroll-item').scrollTop() > scrollDiv1Height +scrollDiv2Height + scrollDiv3Height && $('.scroll-item').scrollTop() < scrollDiv1Height + scrollDiv2Height + scrollDiv3Height + scrollDiv4Height ){
            for(i=0;i<$('.nav-pills li').length;i++){
                $('.nav-pills li').removeClass('active');
            }
            $('.nav-pills li:nth-of-type(4)').addClass('active');

        }else if( $('.scroll-item').scrollTop() > scrollDiv1Height +scrollDiv2Height + scrollDiv3Height + scrollDiv4Height && $('.scroll-item').scrollTop() < scrollDiv1Height + scrollDiv2Height + scrollDiv3Height + scrollDiv4Height + scrollDiv5Height ){
            for(i=0;i<$('.nav-pills li').length;i++){
                $('.nav-pills li').removeClass('active');
            }
            $('.nav-pills li:nth-of-type(5)').addClass('active');
        }else if( $('.scroll-item').scrollTop() > scrollDiv1Height +scrollDiv2Height + scrollDiv3Height + scrollDiv4Height + scrollDiv5Height && $('.scroll-item').scrollTop() < scrollDiv1Height + scrollDiv2Height + scrollDiv3Height + scrollDiv4Height + scrollDiv5Height + scrollDiv6Height ){
            for(i=0;i<$('.nav-pills li').length;i++){
                $('.nav-pills li').removeClass('active');
            }
            $('.nav-pills li:nth-of-type(6)').addClass('active');
        }
    });
})();
/////////////////////////////设置nav-tabs导航项样式///////////////////////////////
(function () {
    var tabsLi = $('.nav-tabs li');
    tabsLi.click(function () {
        for(var i=0;i<tabsLi.length;i++){
            tabsLi.removeClass('active');
        }
        $(this).addClass('active');
    });

})();
/////////////////////////////////////选项卡//////////////////////////////////////
(function () {
    var aDiv = $('.tabs .tabs-content').find('div');
    aDiv.not(':first-child').css('display','none');
    var aLi = $('.tabs .nav-tabs li');
    for(var i=0;i<aLi.length;i++){
        aLi[i].index = i;
    }
    aLi.click(function () {
        for(var i=0;i<aDiv.length;i++){
            aDiv[i].style.display = 'none';
        }
        aDiv[this.index].style.display = 'block';
    });
})();





/////////////////////////////设置nav-pills导航项样式///////////////////////////////
(function () {
    var pillsLi = $('.nav-pills').not('.nav-pills-success,.nav-pills-info,.nav-pills-warning,.nav-pills-danger').children('li');
    pillsLi.click(function () {
        if($(this).hasClass('disabled')){
        }else{
            for(var i=0;i<pillsLi.length;i++){
                pillsLi.removeClass('active');
            }
            $(this).addClass('active');
        }
    });
})();
/////////////////////////////设置nav-pills-success导航项样式///////////////////////////////
(function () {
    var pillsLi = $('.nav-pills').filter('.nav-pills-success').children('li');
    pillsLi.click(function () {
        for(var i=0;i<pillsLi.length;i++){
            pillsLi.removeClass('active');
        }
        $(this).addClass('active');
    });
})();
/////////////////////////////设置nav-pills-info导航项样式///////////////////////////////
(function () {
    var pillsLi = $('.nav-pills').filter('.nav-pills-info').children('li');
    pillsLi.click(function () {
        for(var i=0;i<pillsLi.length;i++){
            pillsLi.removeClass('active');
        }
        $(this).addClass('active');
    });
})();
/////////////////////////////设置nav-pills-warning导航项样式///////////////////////////////
(function () {
    var pillsLi = $('.nav-pills').filter('.nav-pills-warning').children('li');
    pillsLi.click(function () {
        for(var i=0;i<pillsLi.length;i++){
            pillsLi.removeClass('active');
        }
        $(this).addClass('active');
    });
})();
/////////////////////////////设置nav-pills-danger导航项样式///////////////////////////////
(function () {
    var pillsLi = $('.nav-pills').filter('.nav-pills-danger').children('li');
    pillsLi.click(function () {
        for(var i=0;i<pillsLi.length;i++){
            pillsLi.removeClass('active');
        }
        $(this).addClass('active');
    });
})();
/////////////////////////////设置点击触发状态框样式///////////////////////////////
(function () {
    var modalHide = $('[data-modal="modal"] .modal-hide');
    var modalContent = $('[data-modal="modal"] .modal-content');

    modalContent.css('left',$(window).width()/2 - modalContent.width()/2 + 'px');
    $('[data-modal="modal"] .modal-btn').click(function () {
        modalHide.css('display','block');
        modalHide.animate({
            opacity:1
        },300);
        modalContent.css('display','block');
        modalContent.animate({
            opacity:1,
            top:$(window).height()/2 - modalContent.height()/2
        },300);
    });
    modalHide.click(function () {
        modalHide.animate({
            opacity:0
        },300, function () {
            modalHide.css('display','none');
        });

        modalContent.animate({
            opacity:0,
            top:-600
        },300, function () {
            modalContent.css('display','none');
        });
    });
})();
//
(function () {
    var oBtn = $('.navbar-header .navbar-toggle');
    var onOff = true;
    oBtn.click(function () {
        if(onOff){
            $('.navbar-collapse').animate({
                height:240
            });
            onOff = false;
        }else {
            $('.navbar-collapse').animate({
                height:0
            });
            onOff = true;
        }
    });
})();